<?php
////////////////////////////////////////////////////
//	LinBoard
//	write.php
//	Created: 20th March 2009; 20:19 UTC
//	LinBoard (c) Copyright OpenInferno 2008, 2009
////////////////////////////////////////////////////

//Setup Environment
error_reporting(E_ALL | E_STRICT);
define("LINBOARD", true);

//Load Framework
require_once("./Config.php");
require_once(ROOT_PATH . "/Framework/Framework.php");

if(!isset($_GET['mode']))
{
	$_GET['mode'] = "NOTSET";
}

switch($_GET['mode'])
{
	default:
	case 'NOTSET':
		echo "Mode not set.";
	break;
	
	case 'post':
		writePostForm();
	break;
	
	case 'db-post':
		addPostToDB();
	break;
	
	case 'thread':
		writeThreadForm();
	break;
	
	case 'db-thread':
		addThreadToDB();
	break;
}

function writePostForm()
{
	if(Framework::Login()->isLoggedin())
	{
		Framework::Template()->set("tid", $_GET['tid']);
		Framework::Template()->fetch(ROOT_PATH . "/Templates/Default/write_post_form_template.php");
	} else {
		echo "Please login to post here.";
	}
}

function addPostToDB()
{
	$cusr = Framework::User()->getUserDetails();
	if(Framework::Post()->writePost($cusr['uid'], $_POST['postitle'], $_POST['postcontent'], $_GET['tid']))
	{
		echo "Posted!";
	} else {
		echo "An Error Occured!";
	}
}

function writeThreadForm()
{
	if(Framework::Login()->isLoggedin())
	{
		Framework::Template()->set("bid", $_GET['bid']);
		Framework::Template()->fetch(ROOT_PATH . "/Templates/Default/write_thread_form_template.php");
	} else {
		echo "Please login to post here.";
	}
}

function addThreadToDB()
{
	$cusr = Framework::User()->getUserDetails();
	if(Framework::Thread()->addThread($cusr['uid'], $_POST['postitle'], $_POST['postcontent'], $_POST['postdescription'], $_GET['bid']))
	{
		echo "Posted!";
	} else {
		echo "An Error Occured!";
	}
}
?>